install.packages("arules")
install.packages("arulesViz")
install.packages('arulesSequences')
library('arules')
library('arulesViz')
library('arulesSequences')


setwd('/Users/lz/Documents/jinzhou')
#data=read.csv('')
#transactions
jinzhou=read.transactions('jz.csv',format='basket',sep=',')
basketSize=size(jinzhou)

inspect(jinzhou[1:5])
#itemCount=(itemFreq/sum(itemFreq))*sum(basketSize)
itemFrequencyPlot(jinzhou, topN=10, horiz=T,support=0.1)

jinzhourules <- apriori(jinzhou, parameter = list(support = 0.00000001, confidence = 0.0000005, minlen = 3),
                        appearance = list(rhs=c('041610198'))) 
inspect(jinzhourules[1:10])

order_rules=sort(jinzhourules, by='lift')
inspect(order_rules[1:10])


# yogurtrules <- subset(groceryrules, items %in% c(“yogurt”)) 
# 注：%in%是精确匹配; 
# %pin%是部分匹配，也就是说只要item like ‘%A%’ or item like ‘%B%’; 
# %ain%是完全匹配，也就是说itemset has ‘B’ and itemset has ‘B’; 
# 如果仅仅想搜索lhs或者rhs，那么用lhs或rhs替换items即可。
jinzhouselect=jinzhourules
jinzhouselect<-subset(jinzhourules, items %in% c('15640666688'))
inspect(jinzhouselect)


#plot(jinzhouselect, method='scatterplot',control=list(jitter=2, shading = 'lift'))

plot(jinzhouselect,method="graph",control=list(main='aa'))

plot(jinzhouselect,method='grouped', control = list(k=10))
plot(jinzhouselect, method='paracoord')




